# -*- coding: utf-8 -*-
import scrapy
from ..items import Proxy89ipBean,ItemType

class Proxy89ipSpider(scrapy.Spider):
    name = 'proxy89ip'
    allowed_domains = ['89ip.cn']
    #start_urls = ['http://www.89ip.cn/tqdl.html?api=1&num=30&port=&address=%E5%B9%BF%E4%B8%9C&isp=']
    start_urls =['http://www.89ip.cn/tqdl.html?num=300&address=&kill_address=&port=&kill_port=&isp=']
    page_index = 1

    def parse(self, response):

        #print('response>>>{}'.format(response))#
        ip_text_arr = response.xpath('.//div[@class="fly-panel"]/div/text()').extract()
        print('ip_text>>>{}'.format(ip_text_arr))
        ipBean = Proxy89ipBean()
        ipBean['itemName'] = ItemType.PY89IP.value
        ip_text_arr[0] = ip_text_arr[0].strip()
        if len(ip_text_arr) > 4:
            ipBean['proxy89ipList'] = ip_text_arr[:-4]
        yield ipBean